import Api from '@/services/api';
export default {
  data() {
    return {
      
    }
  },
  computed: {
    privacyData() {
      return this.$store.state.privacyData;
    }
  },
  onShow() {
  },
  methods: {
    handleLogin() {
      // 避免数据已经更新 但是还在当前页面的情况
      if (this.privacyData.nickName && this.privacyData.avatarUrl && this.privacyData.phone) {
        uni.showToast({ title: '数据更新成功', icon: 'none' })
        setTimeout(() => {
          this.$Serv.backTargetPage('/pages/quizzes/index', 'switchTab');
        }, 500)
      }
      // 昵称和头像 任何一个没有都弹窗更新
      if (!this.privacyData.nickName || !this.privacyData.avatarUrl) {
        this.$refs.userInfoPopup.togglePopup(true);
      }
    },
    // 获取手机号码回调
    async getPhoneNumber({ iv, encryptedData }) {
      const ret = await this.$request({
        url: Api.decodePhoneData,
        method: 'POST',
        data: { 
          iv, 
          encryptedData,
          sessionKey: this.privacyData.sessionKey
        }
      })
      if (ret.code == 200) {
        this.$store.commit('setStore', {
          privacyData: { 
            phone: ret.result.phone
           }
        })
        uni.showToast({ title: '操作成功', icon: 'none' })
        if (this.privacyData.nickName && this.privacyData.avatarUrl) {
          setTimeout(() => {
            uni.navigateBack();
            // this.$Serv.backTargetPage('/pages/quizzes/index', 'switchTab');
          }, 500)
        }else {
          this.$refs.userInfoPopup.togglePopup(true);
        }
      }
    },

    cancelLogin() {
      console.log('-------------->');
      // uni.clearStorage();
      uni.navigateBack();
      // this.$Serv.backTargetPage('/pages/quizzes/index', 'switchTab');
    }
  }
}